url = 'https://www.acwing.com/problem/content/845/'


def dfs1(u):
    if u == n:
        for i in range(n):
            print(''.join(g[i]))
        print()
        return

    for i in range(n):
        if not col[i] and not dg[u + i] and not udg[n - u + i]:
            g[u][i] = 'Q'
            col[i] = dg[u + i] = udg[n - u + i] = True
            dfs1(u + 1)
            col[i] = dg[u + i] = udg[n - u + i] = False
            g[u][i] = '.'


# 会超出递归的深度
import sys

sys.setrecursionlimit(1 << 31 - 1)


def dfs2(x, y, s):
    if s > n:
        return
    if y == n:
        y = 0
        x += 1
    if x == n:
        if s == n:
            for i in range(n):
                print(''.join(g[i]))
            print()
        return

    g[x][y] = '.'
    dfs2(x, y + 1, s)

    if not row[x] and not col[y] and not dg[x + y] and not udg[x - y + n]:
        row[x] = col[y] = dg[x + y] = udg[x - y + n] = True
        g[x][y] = 'Q'
        dfs2(x, y + 1, s + 1)
        g[x][y] = '.'
        row[x] = col[y] = dg[x + y] = udg[x - y + n] = False


if __name__ == '__main__':
    n = int(input())
    g = [['.' for _ in range(n)] for _ in range(n)]
    col = [False] * n
    row = [False] * n
    dg = [False] * (2 * n)
    udg = [False] * (2 * n)

    # dfs1(0)
    dfs2(0, 0, 0)
